package com.lanou.pianke.admin.web.controller;

import com.lanou.pianke.articlecategory.entity.ACategory;
import com.lanou.pianke.admin.service.ArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class ArticleCategoryController {

    @Autowired
    private ArticleCategoryService articleCategoryService;

    //显示所有文章分类
    @GetMapping("/showArticleCategorys")
    public List<ACategory> showArticleCategorys(){
        return articleCategoryService.showAll();
    }

    //删除选中文章分类
    @DeleteMapping("/deleteCategory/{acid}")
    public String deleteCategory(@PathVariable Long acid){
        articleCategoryService.deleteCategory(acid);
        return "delete successfully";
    }

    //更改文章分类信息(分类中文名,分类英文名,分类背景图片)
    @PutMapping("/updateCategory/{acid}&{acname}&{ecname}&{acimg}")
    public String updateCategory(@PathVariable Long acid,@PathVariable String acname,@PathVariable String ecname,@PathVariable String acimg){
        ACategory articleCategory = articleCategoryService.selectByAcid(acid);
        articleCategory.setAcname(acname);
        articleCategory.setEcname(ecname);
        articleCategory.setAcimg(acimg);
        articleCategoryService.updateByAcid(articleCategory);
        return "update successfully";
    }

    //添加文章分类(分类中文名,分类英文名,分类背景图片)
    @PostMapping("/addCategory/{acname}&{ecname}&{acimg}")
    public String addCategory(@PathVariable String acname,@PathVariable String ecname,@PathVariable String acimg){
        ACategory articleCategory = new ACategory(acname,ecname,0,acimg);
        articleCategoryService.addCategory(articleCategory);
        return "add successfully";
    }

}
